import yolo_train,yolo_predict
from yolo_train import *
from yolo_predict import *


class myMain(QObject):
    font1 = QtGui.QFont("Adobe 黑体 Std R")
    font1.setPixelSize(36)
    font2 = QtGui.QFont("Adobe 黑体 Std R")
    font2.setPixelSize(72)

    def __init__(self):
        super(myMain, self).__init__()
        self.Ytrain = yolo_train.MyWindow()
        self.Ypredict = yolo_predict.myPredict()
        self.create_window()

    def create_window(self):
        self.mainWindow = QMainWindow_new()
        self.mWw = 1200
        self.mWh = 600
        self.mainWindow.resize(self.mWw, self.mWh)
        self.mainWindow.move(400, 400)
        self.mainWindow.setWindowTitle('鸟眼')
        self.mainWindow.setFixedSize(self.mWw, self.mWh)

        self.mainWindow.setWindowIcon(QIcon("./ui/label.jpg"))
        # self.window.setWindowIcon(QIcon(r'ui\image\title.ico'))

        label_backdrop = QLabel(self.mainWindow)
        label_backdrop.resize(self.mWw, self.mWh)
        label_backdrop.setStyleSheet("background-color: rgb(240, 250, 250);")

        label_title = QLabel(self.mainWindow)
        label_title.resize(self.mWw,50)
        label_title.setText("    鸟眼")
        label_title.setFont(QtGui.QFont("Adobe 黑体 Std R", 16))
        label_title.setStyleSheet("background-color: rgb(50, 200, 200);")

        label_T = QLabel(self.mainWindow)
        label_T.resize(40,40)
        label_T.move(5,5)
        label_T.setPixmap(QPixmap(r"ui\label.jpg").scaled(label_T.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))

        button_close = QPushButton(self.mainWindow)
        button_close.setStyleSheet("QPushButton {border: none;}")
        button_close.setIcon(QIcon(r"ui\close.png"))
        button_close.resize(50, 50)
        button_close.move(self.mWw - 50, 0)
        button_close.clicked.connect(self.mainWindow.close)

        button_min = QPushButton(self.mainWindow)
        button_min.setStyleSheet("QPushButton {border: none;}")
        button_min.setIcon(QIcon(r"ui\min.png"))
        button_min.resize(50, 50)
        button_min.move(self.mWw - 100, 0)
        button_min.clicked.connect(self.mainWindow.showMinimized)

        label1 = QLabel(self.mainWindow)
        label1.move(self.mWw // 2 - 200, 70)
        label1.resize(600,200)
        label1.setText("欢 迎 使 用\n  鸟   眼  ")
        label1.setFont(self.font2)

        label_left = QLabel(self.mainWindow)
        label_left.setScaledContents(True)
        label_left.resize(400, 400)
        label_left.move(0, 150)
        movie = QMovie(r"ui\bird_1.gif")
        label_left.setMovie(movie)
        movie.start()

        label_right = QLabel(self.mainWindow)
        label_right.setScaledContents(True)
        label_right.resize(400,400)
        label_right.move(800,150)
        movie = QMovie(r"ui\bird.gif")
        label_right.setMovie(movie)
        movie.start()

        button_train = QPushButton(self.mainWindow)
        button_train.resize(300,100)
        button_train.move(self.mWw//2-150,self.mWh//2)
        button_train.setText("训 练 模 型")
        button_train.setFont(self.font1)
        button_train.clicked.connect(self.train_model)

        button_predict = QPushButton(self.mainWindow)
        button_predict.resize(300, 100)
        button_predict.move(self.mWw//2-150, self.mWh//2+150)
        button_predict.setText("检 测 目 标")
        button_predict.setFont(self.font1)
        button_predict.clicked.connect(self.predict_target)

    def train_model(self):
        self.Ytrain.show()

    def predict_target(self):
        self.Ypredict.mainWindow.show()

if __name__=='__main__':
    QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QApplication([])
    mymain = myMain()
    mymain.mainWindow.show()
    app.exec_()
    sys.exit()